package com.fjec.user.service.impl;

import com.fjec.common.enums.EnumLoginType;
import com.fjec.common.protocol.JsonResult;
import com.fjec.common.shiro.AccountInfo;
import com.fjec.common.shiro.MyUserToken;
import com.fjec.user.service.IDevopsLoginService;
import com.fjec.user.view.LoginVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.springframework.stereotype.Service;

@Service
public class DevopsLoginServiceImpl implements IDevopsLoginService {

    @Override
    public JsonResult login(String userName, String userPwd) {
        AuthenticationToken token = new MyUserToken(userName, userPwd, EnumLoginType.ACCOUNT_PWD, null);
        SecurityUtils.getSubject().login(token);
        // 返回登录view
        LoginVO loginVO = new LoginVO();
//        loginVO.setUserId(AccountInfo.getUserId().toString());
        loginVO.setSessionKey(AccountInfo.getSession().getId().toString());
        loginVO.setRoles(AccountInfo.getRole());
        loginVO.setNickName(AccountInfo.getUserName());
        return JsonResult.success()
                .data(loginVO)
                .build();
    }
}
